// Copyright  2004-2008 Backplane Ltd.
//
// This file is part of Ubiquity formsPlayer
//
// Ubiquity formsPlayer is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3 of the License, or (at your
// option) any later version.
//
// Ubiquity formsPlayer is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License
// along with Ubiquity formsPlayer If not, see <http://www.gnu.org/licenses/>.
//	
//
//   Purpose: implementation of CXFormsParseFormControlInput.
//   $Id$


#include "stdafx.h"
#include "implformControlInput.h"
#include "parseFormControlInput.h"
#include "tags.h"

CXFormsParseFormControlInput::CXFormsParseFormControlInput(CImplFormControlInput* pImpl)
		: CXFormsParseSingleNodeBinding(pImpl)
{
};

CXFormsParseFormControlInput::~CXFormsParseFormControlInput()
{

}

#include "parseLabel.h"
#include "parseAlert.h"
#include "commonchild.h"
void CXFormsParseFormControlInput::CheckElement(IHTMLElement *pElem, BSTR sTag, CImpl* pImpl)
{
	HRESULT hr = S_OK;
	if (TAG_ALERT == sTag && !((CImplFormControlInput*) pImpl)->m_pAlert)
	{
		CImplAlert* pAlert = new CImplAlert();
		CXFormsParseAlert parse(pAlert);
		pAlert->m_pXForms = pImpl->m_pXForms;
		hr = parse.Parse(pElem, pAlert);
		
		if(S_OK == hr)
			hr = pAlert->init(pImpl);

		((CImplFormControlInput*) pImpl)->m_pAlert = pAlert;
	}

	else if (TAG_CAPTION == sTag && !((CImplFormControlInput*) pImpl)->m_pCaption)
	{
		CImplCaption* pCaption = new CImplCaption();
		CXFormsParseCaption parse(pCaption);
		pCaption->m_pXForms = pImpl->m_pXForms;
		hr = parse.Parse(pElem, pCaption);

		if ((S_OK == hr))
		{
			hr = pCaption->init(pImpl);
			CComPtr<IHTMLStyle> pRS;
			//hide it - this used to be handled simply by the parent being a viewlink, 
			//	but it seems to fuck up occasionally.
			CComQIPtr<IHTMLElement2>(pElem)->get_runtimeStyle(&pRS);
			const CComBSTR sNone(L"hidden");
			pRS->put_visibility(sNone);
		}

		((CImplFormControlInput*) pImpl)->m_pCaption = pCaption;
	}

}
